package com.hongyun.sdk.customer.notice.handle;

import com.alibaba.fastjson2.JSON;
import com.hongyun.sdk.common.HYResponse;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class HYStationNoticeHandle {
    /**
     * 处理油站变更请求
     *
     * @param request
     * @return
     */
    public List<String> changeNoticeRequestHandle(HttpServletRequest request) {
        String merchantGasStationIds = request.getParameter("merchantGasStationId");
        if (merchantGasStationIds == null) {
            return new ArrayList<String>();
        }
        return Arrays.asList(merchantGasStationIds.split(","));
    }

    /**
     * 处理油站变更请求返回
     * @param hyResponse
     * @return
     * @throws IOException
     */
    public ResponseEntity changeNoticeResponseHandle(HYResponse hyResponse) throws IOException {
        HttpHeaders headers = new HttpHeaders();
        headers.forEach(hyResponse::put);
        return new ResponseEntity<>(JSON.toJSONString(hyResponse), headers, HttpStatus.OK);
    }



}
